<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@	page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<head>
<style type="text/css">
h1 span{visibility:visible;}
td span{visibility:visible;}
.msg{float:left; line-height:1.5em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
</head>
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.alphanumeric.js"></script>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="${midContextPath}/css/smoothness.datepick.css"/>
<link rel="stylesheet" type="text/css" href="${midContextPath}/css/validator.css"/>
<!-- 時間 -->	
<script src="<%=ServerValue.getMidContextPath()%>/js/jquery.timePicker.js" type="text/javascript"/></script>
<script src="<%=ServerValue.getMidContextPath()%>/ckeditor/ckeditor.js" type="text/javascript"></script>
<script type="text/javascript" charset="UTF-8" src="${midContextPath}/js/jquery.autotab-1.1b.js"></script>
<link rel="stylesheet" type="text/css" href="<%=ServerValue.getMidContextPath()%>/css/timePicker.css"/>
<script language="javascript">
$().ready( function(){
	$(":input[id*='adWord']").alphanumeric();
	$(":input[id*='adWord']").autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });	

	if('${hasurl}'=='Y'){
		$('#ann_tf').show();
		$('#ann_tf_desc').show();
	}
	if('${hasurl}'=='N'){
		$('#ann_tf').hide();
		$('#ann_tf_desc').hide();
		$('#ann_ta_div').show();
	}
	if('${annId}'==''){
		$("h1").eq(0).text('新增公告');
	}

	$('#annShowSeq').numeric();
	$('#startDateParam').datepick({minDate: new Date(<%=request.getAttribute("minDate").toString()%>), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
	$('#endDateParam').datepick({minDate: new Date(<%=request.getAttribute("minDate").toString()%>),showOn: 'both',beforeShow:customRange,numberOfMonths:2, buttonImageOnly: true, buttonImage: '${midContextPath}/images/calendar.gif',dateFormat:"yy-mm-dd"});
	function customRange (){
		var startDt = $('#startDateParam').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}
	$("#startTime").timePicker();
	$("#endTime").timePicker();
	
	$('#radio_y').click(function(){
		$('#ann_tf').show();
		$('#ann_tf_desc').show();
		$('#ann_ta_div').hide();
	});

	$('#radio_n').click(function(){
		$('#ann_tf').hide();
		$('#ann_tf_desc').hide();
		$('#ann_ta_div').show();
	});
	
	$('#submit_button').click(function(){
		var input_error = false;
		
		$("span:[id*=Tip]").hide();
		$("#ann_ta").val(jQuery.trim($("#ann_ta").val()));

		if($('#annNameParam').attr('value').length==0){
			$('#annNameTip').text('标题不能空白');
			$('#annNameTip').show();
			input_error=true;
		}else if(contains($('#annNameParam').val(),'\"', true) || contains($('#annNameParam').val(),"\'",true)){
			$('#annNameTip').text('标题不能含有單引號及雙引號( \" \' )');
			$('#annNameTip').show();
			input_error=true;
		}
		if($('#startDateParam').attr('value').length!=10){
			$('#startDateTip').text('起始日期输入错误');
			$('#startDateTip').show();
			input_error=true;
		}
		if($('#startTime').attr('value').length!=5){
			$('#startTimeTip').text('起始时间输入错误');
			$('#startTimeTip').show();
			input_error=true;
		}
		if($('#endDateParam').attr('value').length!=10){
			$('#endDateTip').text('结束日期输入错误');
			$('#endDateTip').show();
			input_error=true;
		}
		if($('#endTime').attr('value').length!=5){
			$('#endTimeTip').text('结束时间输入错误');
			$('#endTimeTip').show();
			input_error=true;
		}
		if($('#annShowSeq').val().length==0){
			$('#annShowSeqTip').text('请输入显示顺序');
			$('#annShowSeqTip').show();
			input_error=true;
		}
		if($('#radio_y').attr('checked')==true){
			if($('#ann_tf').val().length==0){
				$('#annContexTip').text('URL不能空白');
				$('#annContexTip').show();
				input_error=true;
			}
			if(isURL($('#ann_tf').val())==false){
				$('#annContexTip').text('URL错误');
				$('#annContexTip').show();
				input_error=true;
			}
		}else if($('#radio_n').attr('checked')==true){
			var oEditor = CKEDITOR.instances.ann_ta;
			if(oEditor.getData().length==0){
				$('#annContexTip').text('公告内容不能空白');
				$('#annContexTip').show();
				input_error=true;
			}
		}else{
			$('#annContexTip').text('请选择公告内容');
			$('#annContexTip').show();
			input_error=true;
		}
		if($("#adWord").val()!="" && $("#adWord").val().match(/[^a-zA-Z0-9]/g)){
			$("#adWord").focus();
			$('#annContexTip').text('广告代码只能使用大小写英文字母、数字');
			$('#annContexTip').show();
			input_error=true;
		}
		if(!input_error){
			$("#annForm").submit();
		}
	});

	
});

function isURL(str_url){
	var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
	+ "?(([0-9a-z_!~*'().&amp;=+$%-]+: )?[0-9a-z_!~*'().&amp;=+$%-]+@)?" //ftp的user@
	+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
	+ "|" // 允许IP和DOMAIN（域名）
	+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
	+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
	+ "[a-z]{2,6})" // first level domain- .com or .museum
	+ "(:[0-9]{1,4})?" // 端口- :80
	+ "((/?)|" // a slash isn't required if there is no file name
	+ "(/[0-9a-z_!~*'().;?:@&amp;=+$,%#-]+)+/?)$";
	var re=new RegExp(strRegex);
	if (re.test(str_url)){
		return true;
	}
	return false;
}

function contains(string,substr,isIgnoreCase)
{
    if(isIgnoreCase)
    {
     string=string.toLowerCase();
     substr=substr.toLowerCase();
    }
     var startChar=substr.substring(0,1);
     var strLen=substr.length;
         for(var j=0;j<string.length-strLen+1;j++)
         {
             if(string.charAt(j)==startChar)//如果匹配起始字符,开始查找
             {
                   if(string.substring(j,j+strLen)==substr)//如果从j开始的字符与str匹配，那ok
                   {
                         return true;
                   }  
             }
         }
    return false;
}
</script>
<s:actionerror/>
<s:actionmessage/>
<s:fielderror/>
<br/>
<h1>编辑公告
<span class="f-link"><a href="${midContextPath}/announcement/search.do">回公告列表</a></span>
</h1>

<s:form action="save.do" method="post" id="annForm">
	<table class="tb-data" width="100%">
		<tr>
			<th>#</th>
			<td>${annId}<input type="hidden" name="annId" value="${annId}"></td>
		</tr>
		<tr>
			<th>标题</th>
			<td>
				<input type="text" name="annNameParam" id="annNameParam" value="${annNameParam}" maxlength="27" size="40" />
                (最多二十七字)
                &nbsp;
                &nbsp;
			 	 字体是否强化效果:
				<input type="radio" name="isHighlight" value="Y" id="isHighlight_y" <c-rt:if test="${isHighlight eq 'Y'}">checked="checked"</c-rt:if>/>是 
				<input type="radio" name="isHighlight" value="N" id="isHighlight_n" <c-rt:if test="${isHighlight != 'Y'}">checked="checked"</c-rt:if>/>否  *首页最新快报区以红字加强显示<br/>
				<span id="annNameTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>起始日期</th>
			<td>
				<input name="startDateParam" type="text" id="startDateParam"
				value="${startDateParam}" size="10" maxlength="10">
				<input id="startTime" name="startTime" type="text" value="${startTime}" maxlength="5" size="10" /><br/>
				<span id="startDateTip" class="msg rn" style="display:none;"></span><span id="startTimeTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>结束日期</th>
			<td>
				<input name="endDateParam" type="text" id="endDateParam"
				value="${endDateParam}" size="10" maxlength="10">
				<input id="endTime" name="endTime" type="text" value="${endTime}" maxlength="5" size="10" /><br/>
				<span id="endDateTip" class="msg rn" style="display:none;"></span><span id="endTimeTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>顯示順序</th>
			<td>
				<input id="annShowSeq" name="annShowSeq" type="text" value="${annShowSeq}" maxlength="1" size="5" /><br/>
				<span id="annShowSeqTip" class="msg rn" style="display:none;"></span>
			</td>
		</tr>
		<tr>
			<th>公告类别</th>
			<td>
				<s:select name="annTypeParam" value="%{annTypeParam}"
				list="annTypeMenu.options" listKey="key" listValue="value.name" />
				广告代码：<input type="text" name="adWord" id="adWord" value="${adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span>
			</td>
		</tr>
		<tr>
			<th>公告内容</th>
			<td>
				<input type="radio" name="hasurl" value="Y" id="radio_y" <c-rt:if test="${hasurl eq 'Y'}">checked="checked"</c-rt:if>/>转址URL 
				<input type="radio" name="hasurl" value="N" id="radio_n" <c-rt:if test="${hasurl eq 'N'}">checked="checked"</c-rt:if>/>填写公告内文<br/>
				<div style="width:450px;"><span id="annContexTip" class="msg rn" style="display:none;"></span><br/></div>
				<input id="ann_tf" type="text" name="targetURL" value="${targetURL}" maxlength="100" size="75" style="display:none;"/>
				<span id="ann_tf_desc" style="display:none;"><BR/>请输入完整网址如:http://www.163.com</span>
				<div id="ann_ta_div" style="display:none;">
				<textarea id="ann_ta" rows="10" cols="60" name="anncontent">${anncontent}</textarea>
				<script type="text/javascript">
					CKEDITOR.replace('ann_ta');
					CKEDITOR.config.contentsCss = '/css/yaodian100_news.css';
				</script>
				</div>
			</td>
		</tr>
	</table>
	<input type="button" id="submit_button" value="送出"/>
	<input type="button" onclick="window.location.href='${midContextPath}/announcement/search.do'" value="Cancel"/>
</s:form>